package com.letcoding.spiderAutoHome.job;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.quartz.QuartzJobBean;

@Slf4j
@DisallowConcurrentExecution //Quart定时任务默认都是并发执行的，隔一段时间之后，才会执行。
public class CloseHttpConnectionJob extends QuartzJobBean {
    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        ApplicationContext applicationContext = (ApplicationContext) context.getJobDetail ().getJobDataMap().get("context");
        PoolingHttpClientConnectionManager httpClientPool = applicationContext.getBean (PoolingHttpClientConnectionManager.class);
        httpClientPool.closeExpiredConnections ();
        log.info ("======closeExpiredConnections");
    }
}
